//
//  CTMETableViewController.m
//  百思不得姐
//
//  Created by leo on 2017/5/19.
//  Copyright © 2017年 mine.com. All rights reserved.
//

#import "CTMETableViewController.h"
#import "UIColor+Hex.h"
#import "UIBarButtonItem+CTItem.h"
#import "CTSettingViewController.h"
#import "MJExtension.h"
#import "CTMeDownloadCell.h"
static NSString * const ID = @"cell";
@interface CTMETableViewController () <UICollectionViewDataSource>
@property (nonatomic, weak) UICollectionView *collectionView;
@property (nonatomic, strong) NSArray *downloadItems;
@end

@implementation CTMETableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = CTRandomColor;
    [self setUpNavigationBar];
    [self setFooterView];
    
}

- (void)setUpNavigationBar {
    self.navigationItem.title = @"我的";
    UIBarButtonItem *night = [UIBarButtonItem itemWithNormalImage:[UIImage imageNamed:@"mine-moon-icon"] highLightImage:[UIImage imageNamed:@"mine-moon-icon-click"] target:self action:@selector(night:)];
    UIBarButtonItem *setting = [UIBarButtonItem itemWithNormalImage:[UIImage imageNamed:@"mine-setting-icon"] highLightImage:[UIImage imageNamed:@"mine-setting-icon-click"] target:self action:@selector(setting:)];
    self.navigationItem.rightBarButtonItems = @[setting,night];
}
- (void)night:(UIButton *)button {
    NSLog(@"点击了黑夜按钮");
    
}
- (void)setting:(UIButton *)button {
    CTSettingViewController *settingVc = [[CTSettingViewController alloc] init];
    settingVc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:settingVc animated:YES];
}
- (void)setFooterView {
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    CGFloat margin = 1;
    int column = 4;
    CGFloat cellWH = (CTScreenW - margin * (column - 1)) / column;
    flowLayout.itemSize = CGSizeMake(cellWH, cellWH);
    flowLayout.minimumLineSpacing = margin;
    flowLayout.minimumInteritemSpacing = margin;
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 300) collectionViewLayout:flowLayout];
    _collectionView = collectionView;
    collectionView.dataSource = self;
    [collectionView registerNib:[UINib nibWithNibName:@"CTMeDownloadCell" bundle:nil] forCellWithReuseIdentifier:ID];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -  data source

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.downloadItems.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CTMeDownloadCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    cell.downloadItem = _downloadItems[indexPath.row];
    return cell;
    
}


@end
